package com.ti.winona.ui.fragment;

import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;
import com.taplinker.client.R;
import com.ti.winona.util.FragmentOperateUtil;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

public class HomeFragment extends Fragment {
	
	public final static String TAG = "HomeFragment";
	
	private View mHomeFragmentView;
	
	private View mRelHomConversation;
	private View mLinHomeAcademic;
	private View mLinHomePertool;
	private View mLinHomePersonalset;
	
	private ImageView mImgHomeOptionsMenu;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return mHomeFragmentView = inflater.inflate(R.layout.fragment_home, container, false);
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		
		findView();
		initListner();
	}
	
	private void findView() {
		mRelHomConversation = (View) mHomeFragmentView.findViewById(R.id.rel_home_conversation);
		mLinHomeAcademic = (View) mHomeFragmentView.findViewById(R.id.lin_home_academic);
		mLinHomePertool = (View) mHomeFragmentView.findViewById(R.id.lin_home_pertool);
		mLinHomePersonalset = (View) mHomeFragmentView.findViewById(R.id.lin_home_personalset);
		
		mImgHomeOptionsMenu = (ImageView) mHomeFragmentView.findViewById(R.id.img_home_options_menu);
	}
	
	private void initListner() {
		// 我的会话
		mRelHomConversation.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				addFragment(IMQueueFragment.class, IMQueueFragment.TAG);
			}
		});
		// 学术中心
		mLinHomeAcademic.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				addFragment(AcademicFragment.class, AcademicFragment.TAG);
			}
		});
		// 个人工具
		mLinHomePertool.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				addFragment(PerToolFragment.class, PerToolFragment.TAG);
			}
		});
		// 个人设置
		mLinHomePersonalset.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				addFragment(PerSetFragment.class, PerSetFragment.TAG);
			}
		});
		// Menu开关
		mImgHomeOptionsMenu.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				((SlidingFragmentActivity)getActivity()).toggle();	// 切换Menu按钮
			}
		});
	}
	
	private void addFragment(Class<? extends Fragment> clazz, String tag) {
		FragmentOperateUtil.replaceFragmentWithAnim(getActivity().getSupportFragmentManager(), clazz, R.id.main_frame, tag, null, true);
	}
	
}
